package hz.mobileproject.pda.toolsmanager.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.toolsmanager.bean.response.RQ_SelByStatonList;
import hz.mobileproject.pda.ui.base.BaseCustomAdapter;

/**
 * Created by Lc on 2018/5/4.
 */

public class ToolsBianGengLVAdaper extends BaseCustomAdapter<RQ_SelByStatonList.MyToolData,ToolsBianGengLVAdaper.ViewHolder> {

    public ToolsBianGengLVAdaper(Context mContext, List<RQ_SelByStatonList.MyToolData> list) {
        super(mContext, list);
    }

    @Override
    protected int bindView() {
        return R.layout.item_tools_biangeng_lv;
    }

    @Override
    protected ViewHolder createViewHolder() {
        return new ViewHolder();
    }

    @Override
    protected void bindData(int position, View convertView, ViewHolder viewHolder) {
        viewHolder.mPosition = position;
        viewHolder.tv_toolType.setText(mList.get(position).tool_type+"");
        viewHolder.tv_toolName.setText(mList.get(position).tool_name);
        if(mList.get(position).isScan) {
            //扫描到了
            viewHolder.tv_biangeng_status.setText("变更清点");
            viewHolder.tv_biangeng_status.setTextColor(Color.parseColor("#00ff00"));
        }else {
            viewHolder.tv_biangeng_status.setText("待变更");
            viewHolder.tv_biangeng_status.setTextColor(Color.parseColor("#ff0000"));
        }
    }

    /**
     * 扫描到了列表中的工具
     * @param
     * @param myToolData
     * @param isScan
     */
    public void setToolStatus(int pos, RQ_SelByStatonList.MyToolData myToolData, boolean isScan) {
        if(isScan) {
            myToolData.isScan = true;
        }
        notifyDataSetChanged();
    }


    public List<RQ_SelByStatonList.MyToolData> getScanList() {
        List<RQ_SelByStatonList.MyToolData> scanList = new ArrayList<>();
        for(int i = 0; i < mList.size();i++) {
            if(mList.get(i).isScan) {
                scanList.add(mList.get(i));
            }
        }
        return scanList;
    }



    class ViewHolder{
        @ViewInject(R.id.tv_toolType)
        private TextView tv_toolType;
        @ViewInject(R.id.tv_toolName)
        private TextView tv_toolName;
        @ViewInject(R.id.tv_biangeng_status)
        private TextView tv_biangeng_status;

        private int mPosition;

    }
}
